package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.CheckOutRecord;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.CheckOutRecordService;

@RestController
@RequestMapping("/checkout")
public class CheckOutRecordController {

    @Autowired
    private CheckOutRecordService checkOutRecordService;

    /**
     * 根据审核状态查询外出记录
     * @param status 审核状态 (0:已提交, 1:审核通过, 2:审核不通过)
     * @return 返回包含外出记录列表的 ResponseBean
     */
    @GetMapping("/status/{status}")
    public ResponseBean<List<CheckOutRecord>> getCheckOutRecordsByStatus(@PathVariable Integer status) {
        List<CheckOutRecord> records = checkOutRecordService.getCheckOutRecordsByStatus(status);
        return new ResponseBean<>(records);
    }

    /**
     * 通过客户姓名模糊查询外出记录
     * @param name 客户姓名
     * @return 返回包含外出记录列表的 ResponseBean
     */
    @GetMapping("/searchByName/{name}")
    public ResponseBean<List<CheckOutRecord>> searchCheckOutRecordsByName(@PathVariable String name) {
        List<CheckOutRecord> records = checkOutRecordService.searchCheckOutRecordsByName(name);
        return new ResponseBean<>(records);
    }

    /**
     * 获取所有外出记录
     * @return 返回包含外出记录列表的 ResponseBean
     */
    @GetMapping("/all")
    public ResponseBean<List<CheckOutRecord>> getAllCheckOutRecords() {
        List<CheckOutRecord> records = checkOutRecordService.getAllCheckOutRecords();
        return new ResponseBean<>(records);
    }

    /**
     * 添加外出记录
     * @param checkOutRecord 外出记录对象
     * @return 返回添加结果的 ResponseBean
     */
    @PostMapping("/add")
    public ResponseBean<Boolean> addCheckOutRecord(@RequestBody CheckOutRecord checkOutRecord) {
        boolean result = checkOutRecordService.addCheckOutRecord(checkOutRecord);
        return new ResponseBean<>(result);
    }

    /**
     * 更新外出记录
     * @param checkOutRecord 外出记录对象
     * @return 返回更新结果的 ResponseBean
     */
    @PutMapping("/update")
    public ResponseBean<Boolean> updateCheckOutRecord(@RequestBody CheckOutRecord checkOutRecord) {
        boolean result = checkOutRecordService.updateCheckOutRecord(checkOutRecord);
        return new ResponseBean<>(result);
    }
    /**
     * 根据客户 ID 查询外出记录
     * @param customerId 客户的唯一标识符
     * @return 包含符合条件的外出记录列表的 ResponseBean
     */
    @GetMapping("/customer/{customerId}")
    public ResponseBean<List<CheckOutRecord>> getOutRecordsByCustomerId(@PathVariable Integer customerId) {
        List<CheckOutRecord> CheckoutRecords = checkOutRecordService.getCheckOutRecordsByCustomerId(customerId);
        return new ResponseBean<>(CheckoutRecords);
    }

    /**
     * 根据 ID 逻辑删除外出记录
     * @param id 外出记录的唯一标识符
     * @return 删除结果的 ResponseBean
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean<Boolean> deleteOutRecord(@PathVariable Integer id) {
        boolean result = checkOutRecordService.deleteCheckOutRecord(id);
        return new ResponseBean<>(result);
    }
}